<template>
  <div class="app-container">
    
    <!-- 审核对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">

        <el-form-item label="货转审核" prop="goodsTransferStatus">
          <el-radio-group v-model="form.goodsTransferStatus">
            <el-radio
              v-for="dict in dict.type.audit_pass_return"
              :key="dict.value"
              :label="dict.value"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="退回原因" prop="goodsTransferReturnReason">
          <el-input v-model="form.goodsTransferReturnReason" placeholder="请输入退回原因" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { auditTransfer } from "@/api/transfers/transfer";


export default {
  name: "Audit",
  dicts: ['audit_pass_return'],
  data() {
    return {
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 表单参数
      form: {},
      //货转编号
      goodsTransferId: 0,
      //选中行
      goodsTransferRow: [],
      // 表单校验
      rules: {
/*        postName: [
          { required: true, message: "岗位名称不能为空", trigger: "blur" }
        ],
        postCode: [
          { required: true, message: "岗位编码不能为空", trigger: "blur" }
        ],
        postSort: [
          { required: true, message: "岗位顺序不能为空", trigger: "blur" }
        ]*/
      }
    };
  },
  created() {
  
  },
  methods: {
    init(open, title, goodsTransferId, goodsTransferRow) {
      this.open = open;
      this.title = title;
      this.goodsTransferId = goodsTransferId;
      this.goodsTransferRow = goodsTransferRow;
      //console.log("this.goodsTransferRow", this.goodsTransferRow);
      this.$set(this.form, 'goodsTransferId', this.goodsTransferId);
      this.$set(this.form, 'goodsTransferNumber', this.goodsTransferRow.goodsTransferNumber);
      this.$set(this.form, 'originGoodsRightCustomer', this.goodsTransferRow.originGoodsRightCustomer);
      this.$set(this.form, 'newGoodsRightCustomer', this.goodsTransferRow.newGoodsRightCustomer);
      //this.$set(this.form, 'goodsTransferPicture', this.goodsTransferRow.goodsTransferPicture);
      this.$set(this.form, 'goodsTransferSettlementCustomer', this.goodsTransferRow.originGoodsRightCustomer);
      this.$set(this.form, 'goodsTransferStatus', '1');
      this.$set(this.form, 'originTransferStatus', this.goodsTransferRow.goodsTransferStatus);
      this.$set(this.form, 'goodsTransferTime', this.goodsTransferRow.goodsTransferTime);
      this.$set(this.form, 'createBy', this.goodsTransferRow.createBy);
      this.$set(this.form, 'remark', this.goodsTransferRow.remark);

      this.$set(this.form, 'bundleNumber', this.goodsTransferRow.bundleNumber);
      this.$set(this.form, 'goodsType', this.goodsTransferRow.goodsType);
      this.$set(this.form, 'product', this.goodsTransferRow.product);
      this.$set(this.form, 'specification', this.goodsTransferRow.specification);
      this.$set(this.form, 'goodsTransferWeight', this.goodsTransferRow.goodsTransferWeight);
      this.$set(this.form, 'logisticsParkName', this.goodsTransferRow.logisticsParkName);
      this.$set(this.form, 'warehouseLocateName', this.goodsTransferRow.warehouseLocateName);
      this.$set(this.form, 'regionLocateName', this.goodsTransferRow.regionLocateName);
      //this.$set(this.form, 'bundleNumber', this.goodsTransferRow.bundleNumber);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        goodsTransferId: null,
        goodsTransferNumber: null,
        originGoodsRightCustomer: null,
        newGoodsRightCustomer: null,
        //goodsTransferPicture: null,
        goodsTransferSettlementCustomer: null,
        goodsTransferReturnReason: null,
        goodsTransferStatus: '1',
        goodsTransferTime: null,
        originTransferStatus: null,
        createBy: null,
        remark: null,      
      };
      this.resetForm("form");
    },

    /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
//          console.log('this.form', this.form);

          auditTransfer(this.form).then(response => {
            //this.$modal.msgSuccess("审核成功");
            this.$modal.msgSuccess(response.msg);
            this.open = false;
            this.$parent.getList();
          }).catch((e) => {
            console.log('e', e);
            //this.$modal.msgError(response.msg);
          });

        }
      });
    },

  }
};
</script>
